<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 100%;
            border: 1px solid #ccc;
            border-collapse: collapse;
            border-spacing: 0px;
        }

        table td {
            border: 1px solid #ccc;
            height: 30px;
        }
    </style>
</head>

<body>
    1.完善表格（有复制和删除按钮）
    <span>行：</span>
    <input type="number" name="" id="" class="i1">
    <span>列：</span>
    <input type="number" name="" id="" class="i2">
    <button class="b1">生成</button>
    <div class="bg">

    </div>

    <script src="../js/1.js"></script>
    <script>
        let i1 = document.querySelector(".i1");
        let i2 = document.querySelector(".i2");
        let b1 = document.querySelector(".b1");
        let bg = document.querySelector(".bg");



        let shengcheng = () => {
            let t1 = document.createElement('table');
            let t2 = document.createElement('tbody');

            t1.appendChild(t2);
            let nn = 0

            let ii1 = i1.value;
            let ii2 = i2.value;
            for (let i = 0; i < ii1; i++) {
                let tr = document.createElement("tr");
                if (i % 2 != 0) {
                    tr.style.background = "greenyellow"
                }
                for (let j = 0; j < ii2; j++) {
                    let td = document.createElement("td");
                    td.innerHTML = "这是第" + (i + 1) + "行" + "第" + (j + 1) + "列";
                    tr.appendChild(td)
                    nn = j + 1;
                }
                let zui = tr.insertCell(nn)
                zui.innerHTML = `<a href="#" class="del">删除 </a><a href="#" class="cj">创建</a>`

                t1.appendChild(tr)
            }
            let cj1 = t1.getElementsByClassName("cj");
            console.log(cj1)
            let dfn = t1.getElementsByClassName("del");

            function dd() {
                let tr = t1.getElementsByTagName("tr");
                for (let i = 0; i < dfn.length; i++) {
                    dfn[i].onclick = function () {
                        t1.removeChild(this.parentNode.parentNode);
                    }
                }
            }
            dd();

            function fuzhi() {

                let tr = t1.getElementsByTagName("tr");
                for (let i = 0; i < cj1.length; i++) {
                    cj1[i].onclick = function () {
                        let futr = tr[i].cloneNode(true);
                        t1.appendChild(futr);
                        dd();
                        fuzhi();
                    }
                }
            }
            fuzhi()
            bg.appendChild(t1);
        }

        shijian(b1, "click", shengcheng)
    </script>
</body>

</html>